{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cover the remaining topics of the Differernt things"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# Generators "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python Genrators is a kind of function which gives itereable object in the return\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "83\n",
      "37\n",
      "5\n",
      "47\n",
      "53\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "import sympy\n",
    "\n",
    "print(sympy.randprime(0, 100))  # Output : 83 \n",
    "print (sympy.randprime(0, 100) ) # Output : 41 \n",
    "print (sympy.prime(3))           # Output : 5 \n",
    "print (sympy.prevprime(50))      # Output : 47 \n",
    "print (sympy.nextprime(50) )\n",
    "print(sympy.isprime(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def checkPrimeNumber(num):\n",
    "    if sympy.isprime(num):\n",
    "        return num\n",
    "    else:\n",
    "        return(\"No Prime\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Make a Function to check weather a number is prime or not \n",
    "# if it is prime return that Number \n",
    "# else return a String - \"No Prime\"\n",
    "# collect all the result into a Iterrable object i.e List \n",
    "\n",
    "# Now the Question is without using List.append or \n",
    "# list how can we get a iterablle oject\n",
    "\n",
    "lst = list('')\n",
    "for i in range(1,100):\n",
    "    result = checkPrimeNumber(i)\n",
    "    lst.append(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['No Prime',\n",
       " 2,\n",
       " 3,\n",
       " 'No Prime',\n",
       " 5,\n",
       " 'No Prime',\n",
       " 7,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 11,\n",
       " 'No Prime',\n",
       " 13,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 17,\n",
       " 'No Prime',\n",
       " 19,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 23,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 29,\n",
       " 'No Prime',\n",
       " 31,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 37,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 41,\n",
       " 'No Prime',\n",
       " 43,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 47,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 53,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 59,\n",
       " 'No Prime',\n",
       " 61,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 67,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 71,\n",
       " 'No Prime',\n",
       " 73,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 79,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 83,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 89,\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 'No Prime',\n",
       " 97,\n",
       " 'No Prime',\n",
       " 'No Prime']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def checkPrimeNumber():\n",
    "    for i in range(1,100):\n",
    "        if sympy.isprime(i):\n",
    "            yield i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<generator object checkPrimeNumber at 0x11252ae50>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "checkPrimeNumber()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2,\n",
       " 3,\n",
       " 5,\n",
       " 7,\n",
       " 11,\n",
       " 13,\n",
       " 17,\n",
       " 19,\n",
       " 23,\n",
       " 29,\n",
       " 31,\n",
       " 37,\n",
       " 41,\n",
       " 43,\n",
       " 47,\n",
       " 53,\n",
       " 59,\n",
       " 61,\n",
       " 67,\n",
       " 71,\n",
       " 73,\n",
       " 79,\n",
       " 83,\n",
       " 89,\n",
       " 97]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(checkPrimeNumber())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Without using List or Dict, or any Iterator object u want to get the \n",
    "# output in a list or Iterator object from a Fuction.... \n",
    "\n",
    "# How is it possble the ansewer is Generator\n",
    "\n",
    "\n",
    "#In which u get the return as hte Iterator object made dynamically in the function \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "def checkPrimeNumber():\n",
    "    for i in range(1,100):\n",
    "        if sympy.isprime(i):\n",
    "            return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "checkPrimeNumber()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# can we have a Function which return 3-4 things ?\n",
    "\n",
    "def someFun():\n",
    "    return \"ABc\"\n",
    "    return \"xyz\"\n",
    "    return \"qpr\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ABc'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "someFun()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "def someFun():\n",
    "    yield \"ABc\"\n",
    "    yield \"xyz\"\n",
    "    yield \"qpr\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['ABc', 'xyz', 'qpr']"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(someFun())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# OOP  Topics /"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Lets build a class known as square \n",
    "\n",
    "\n",
    "class square:\n",
    "    \n",
    "    perimeterVal= 4\n",
    "    \n",
    "    def __init__(self,side= 3):\n",
    "        self.side = side\n",
    "        \n",
    "    def perimeterOfSquare(self):\n",
    "        return self.side * self.perimeterVal\n",
    "    \n",
    "    def areaOfSquare(self):\n",
    "        return self.side * self.side\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "ourSquare = square(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "36"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ourSquare.areaOfSquare()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ourSquare.perimeterOfSquare()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Inheritance "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "# what is inheritance ?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Parent Class \n",
    "class cat:\n",
    "    def __init__ (self,name):\n",
    "        self.name = name\n",
    "        print(self.name +\" Cat got created from parent\")\n",
    "    def talk(self):\n",
    "        return self.name + ' Says Meeowww'\n",
    "    \n",
    "#Child Class inheriting properties form CAT Class \n",
    "class persian_Cat(cat):\n",
    "    def __init__(self):\n",
    "        cat.__init__(self,'Persian Cat')\n",
    "        print(\"persian_Cat Got Created\")\n",
    "    def lifeSpan(self):\n",
    "        print(\"Life Span = 10-17\")\n",
    "\n",
    "#Child Class inheriting properties form CAT Class \n",
    "class himalayan_cat(cat):\n",
    "    def __init__(self):\n",
    "        cat.__init__(self,'Himalayan Cat')\n",
    "        print(\"Himalayan cat Got Created\")\n",
    "    def lifeSpan(self):\n",
    "        print(\"Life Span = 9-15\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Persian Cat Cat got created from parent\n",
      "persian_Cat Got Created\n"
     ]
    }
   ],
   "source": [
    "p = persian_Cat()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Himalayan Cat Cat got created from parent\n",
      "Himalayan cat Got Created\n"
     ]
    }
   ],
   "source": [
    "h = himalayan_cat()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Persian Cat'"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Himalayan Cat'"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Persian Cat Says Meeowww'"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p.talk()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Himalayan Cat Says Meeowww'"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h.talk()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Life Span = 10-17\n"
     ]
    }
   ],
   "source": [
    "p.lifeSpan()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Life Span = 9-15\n"
     ]
    }
   ],
   "source": [
    "h.lifeSpan()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jambo African Elephant Says D. Trump\n",
      "Alexandar percheron Says Tarun\n"
     ]
    }
   ],
   "source": [
    "class Animal():\n",
    "    def __init__(self,name,breed):\n",
    "        self.name = name \n",
    "        self.breed = breed\n",
    "    \n",
    "    def speak(self):\n",
    "        raise NotImplementedError(\"Sub Class Must Implement Speak Method\")\n",
    "\n",
    "class Elephant(Animal):\n",
    "    def speak(self):\n",
    "        return self.name + self.breed + ' Says D. Trump'\n",
    "\n",
    "\n",
    "class Horse(Animal):\n",
    "    def speak(self):\n",
    "        return self.name + self.breed+ ' Says Tarun'\n",
    "    \n",
    "Jambo = Elephant('Jambo',' African Elephant')\n",
    "Alexandar = Horse('Alexandar',' percheron')\n",
    "\n",
    "print(Jambo.speak())\n",
    "print(Alexandar.speak())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# polymorphism"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "# same name but differnt works "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Animal():\n",
    "    def __init__(self,name,breed):\n",
    "        self.name = name\n",
    "        self.breed = breed\n",
    "    \n",
    "    def speak(self):\n",
    "        raise NotImplementedError(\"Sub Class Must Implement Speak Method\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "class cheetah(Animal):\n",
    "    def __init__(self,name,breed):\n",
    "        Animal.__init__(self,name,breed)\n",
    "    def speak(self):\n",
    "        print(\"Cheetah do MEOW\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "class lion(Animal):\n",
    "    def __init__(self,name,breed):\n",
    "        Animal.__init__(self,name,breed)\n",
    "    def speak(self):\n",
    "        print(\"Lion do ROAR\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = lion(\"Cubby\",\"B\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = cheetah(\"Buddy cheetah\",'A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Lion do ROAR\n"
     ]
    }
   ],
   "source": [
    "l.speak()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cheetah do MEOW\n"
     ]
    }
   ],
   "source": [
    "c.speak()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "ename": "NotImplementedError",
     "evalue": "Hey Kumar Kanan U need to implement Speak in Baseclass",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNotImplementedError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-45-033fb56808fb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Hey Kumar Kanan U need to implement Speak in Baseclass\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNotImplementedError\u001b[0m: Hey Kumar Kanan U need to implement Speak in Baseclass"
     ]
    }
   ],
   "source": [
    "raise NotImplementedError(\"Hey Kumar Kanan U need to implement Speak in Baseclass\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sunday The Exam date is ----  17 of May, \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# from 11 AM to 1:30 PM "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
